
#include <iostream>
#include <typeinfo>
using namespace std;

int a = 10;
class Y {
public:
	Y():e(50) {}
	void foo( int c=30 ) {
		cout << "-----------[]----------" << endl;
		[](int d=40){
			cout << "a = " << a << endl;
			cout << "b = " << b << endl;
//			cout << "c = " << c << endl;	err
			cout << "d = " << d << endl;
//			cout << "e = " << e << endl;	err
		}();
		/*
		class x {
		public:
			void operator()( int d = 40 ) {
				cout << "a = " << a << endl;
				cout << "b = " << b << endl;
//				cout << "c = " << c << endl;	err
				cout << "d = " << d << endl;
//				cout << "e = " << e << endl;	err
			}
		};
		x{}();
		*/
		
		// Catch the value of c.
		cout << "-----------[c]----------" << endl;
		[c]( int d = 40 ) { cout << "c = " << c << endl; }();
		/*
		 * class xx {
		 * public:
		 * 	xx(int m):c(m) {}
		 * 	void operator()( int d=40 ) {
		 *		cout << "c = " << c << endl;
		 * 	}
		 * private:
		 * 	const int c; 	// This is not the c in foo.
		 * };
		 * xx{c}();	// This is the c int foo.
		 */

		cout << "-----------[&c]----------" << endl;
		[&c]( int d = 40 ) { cout << "c = " << ++c << endl; }();
		/*
		 * class xxxx {
		 * public:
		 * 	xxxx(int& m):c( m ) {}
		 * 	void operator()( int d = 40 ) {
		 *		cout << "c = " << c << endl;
		 * 	}
		 * private:
		 * 	int& c; 	// This is not the c in foo.
		 * };
		 * xxxx{ c }( );	// This is the c int foo.
		 */

		cout << "-----------[this]----------" << endl;
		[this]( int d = 40 ) { cout << "e = " << e << endl; }();
	}
private:
	static int b;
	int e;
};
int Y::b = 20;


int main( void ) {
	Y y;
	y.foo();

	return 0;
}

